package com.cheng.example.atguigu.design_pattern.principle.demeter;

/*
 * @author 程帅
 * @createTime: 2020/10/18 21:32
 * @Created: with IntelliJ IDEA.
 */

import java.util.ArrayList;
import java.util.List;

//客户端
public class Demeter1 {

    public static void main(String[] args) {
        SchoolManager schoolManager = new SchoolManager();
        schoolManager.printAllEmployee(new CollegeManager());
    }

}

//学校总部员工类
class Employee{
    private String id;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}

//学院的员工类
class CollegeEmployee{
    private String id;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}

//管理学院员工的管理类
class CollegeManager{

    //返回学院的所有员工
    public List<CollegeEmployee> getAllEmployee() {
        ArrayList<CollegeEmployee> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) { //这里我们增加了10个员工到list
            CollegeEmployee emp = new CollegeEmployee();
            emp.setId("学院员工id=" + i);
            list.add(emp);
        }
        return list;
    }
}

//学校管理类
class SchoolManager{
    //返回学校总部的员工
    public List<Employee> getAllEmployee() {
        ArrayList<Employee> list = new ArrayList<>();
        for (int i = 0; i < 5; i++) { // 这里我们增加了5个员工到list
            Employee emp = new Employee();
            emp.setId("学校总部员工id= " + i);
            list.add(emp);
        }
        return list;
    }
    //该方法完成输出学校总部和员工信息（id）
    void printAllEmployee(CollegeManager sub) {
        //分析问题
        //1.这里CollegeEmployee 不是 SchoolManager的直接朋友
        //2.CollegeEmployee 是以局部变量方式出现在 SchoolManger
        //3.违反了迪米特法则
        //获取到学院员工
        List<CollegeEmployee> list1 = sub.getAllEmployee();
        System.out.println("-------学院员工-------");
        for (CollegeEmployee e : list1) {
            System.out.println(e.getId());
        }
        //获取到学校总部员工
        List<Employee> list2 = this.getAllEmployee();
        System.out.println("------学校总部员工-----");
        for (Employee e : list2) {
            System.out.println(e.getId());
        }
    }
}